//
//  LGFollowStopMedicineController.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/7/13.
//  停药原因

#import "LGFollowStopMedicineController.h"
#import <IQKeyboardManager/IQKeyboardManager.h>
#define placeHolder  @"请输入..."
@interface LGFollowStopMedicineController ()<UITextViewDelegate>
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UITextView *textView;
/**   */
@property (nonatomic , strong)UIButton *saveButton;

@end

@implementation LGFollowStopMedicineController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"停药原因";
    [IQKeyboardManager sharedManager].enableAutoToolbar = YES;
    [self.view addSubview:self.baseView];
    [self.view addSubview:self.saveButton];
    [self.baseView addSubview:self.titleLabel];
    [self.baseView addSubview:self.textView];
    
}


//保存
-(void)saveBtnAction{
    if(self.textView.text.length==0||[self.textView.text  isEqualToString:placeHolder]){
        [TooltipView showMessage:@"请输入停药原因" offset:0];
        return;
    }
    if(self.stopDescFillComplete){
        self.stopDescFillComplete(self.textView.text, self.index);
    }
    [self.navigationController popViewControllerAnimated:YES];
}


-(void)setContent:(NSString *)content{
    _content = content;
    self.textView.text = content;
    if(content.length == 0 || [content isEqualToString:placeHolder]){
        self.textView.text = placeHolder;
        self.textView.textColor = [UIColor colorWithString:@"#9595A0"];
    }else{
        self.textView.textColor = [UIColor colorWithString:@"#333333"];
    }
}

- (void)textViewDidBeginEditing:(UITextView *)textView{
    self.textView.textColor = [UIColor colorWithString:@"#333333"];
    if([textView.text isEqualToString:placeHolder]){
        self.textView.text = @"";
    }
}
- (void)textViewDidEndEditing:(UITextView *)textView{
    NSString *content = textView.text;
    if(content.length == 0||[textView.text isEqualToString:placeHolder]){
        self.textView.text = placeHolder;
        self.textView.textColor = [UIColor colorWithString:@"#9595A0"];
    }else{
        self.textView.textColor = [UIColor colorWithString:@"#333333"];
    }
}

- (void)textViewDidChange:(UITextView *)textView{
    if(textView.text.length>500){
        textView.text = [textView.text substringToIndex:500];
    }
//    self.numberLabel.text = [NSString stringWithFormat:@"%ld / 500",textView.text.length];
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _baseView.frame = CGRectMake(viewPix(16), viewPix(16), Screen_W-viewPix(32), viewPix(235));
        _baseView.backgroundColor = [UIColor whiteColor];
        _baseView.cornerRidus = 15;
    }
    return _baseView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"停药原因" colorString:@"#333333" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        _titleLabel.frame = CGRectMake(viewPix(16), viewPix(16), viewPix(80), viewPix(23));
    }
    return _titleLabel;
}

-(UITextView *)textView{
    if(!_textView){
        _textView = [[UITextView alloc]initWithFrame:CGRectMake(0, viewPix(40), Screen_W-viewPix(32), viewPix(190))];
        _textView.contentInset = UIEdgeInsetsMake(0, viewPix(12), viewPix(10), viewPix(12));
        _textView.tintColor = [UIColor colorWithString:@"#666666"];
        _textView.textColor = [UIColor colorWithString:@"#999999"];
        _textView.textAlignment = NSTextAlignmentLeft;
        _textView.text = placeHolder;
        _textView.font = LGFont(14);
        _textView.delegate = self;
    }
    return _textView;
}

-(UIButton *)saveButton{
    if(!_saveButton){
        _saveButton = [UIButton buttonWithTitle:@"确认" topMargin:Screen_H-topBarHeight-viewPix(80)];
        [_saveButton addTarget:self action:@selector(saveBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _saveButton;
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
